<template>
  <br>
  <el-card style="margin: 20px;height: 70px;background-color:#e1f3d8 ;width: 1100px ">
    <el-form :inline="true">
      <el-form-item label="投诉ID">
        <el-input placeholder="请输入投诉ID"
                  style="width: 220px;" v-model="searchComplaintForm.complaintId" @keydown.enter="loadComplaint"></el-input>
      </el-form-item>

      <el-form-item >
        <el-button @click="resetSearch">重置</el-button>
        <el-button color="#42b983" style="color: #f4f7f6" @click="loadComplaint">查询</el-button>
      </el-form-item>
    </el-form>
  </el-card>
  <!-- 显示用户信息表格 -->
  <el-card style="margin:20px;background-color: #e1f3d8;width: 1100px">
    <el-table :data="ComplaintArr">
      <el-table-column prop="complaintId" label="投诉ID" width="80" align="center" ></el-table-column>
      <el-table-column prop="orderId" label="订单ID" align="center"></el-table-column>
      <el-table-column prop="complaintInfo" label="投诉信息" align="center"></el-table-column>
    </el-table>
  </el-card>

</template>

<script setup>
import {onMounted, ref} from "vue";
import qs from "qs";
import axios from "axios";
import {ElMessage} from "element-plus";


//定义对象保存查询条件
const ComplaintArr = ref([]);
const searchComplaintForm = ref({ComplaintId: ''})
//定义加载用户的方法
const loadComplaint = () => {
  //有条件则根据条件查投诉数据,没有条件默认查所有投诉数据
  let data = qs.stringify(searchComplaintForm.value);
  axios.get(BASE_URL + '/v1/complaint/select?' + data).then((response) => {
    if (response.data.code == 2000) {
      ComplaintArr.value = response.data.data;
    }else {
      ElMessage.error(response.data.msg);
    }
  })
}
//页面一加载立即请求加载投诉数据
onMounted(() => {
  loadComplaint();
})
//重置用户搜索信息
const resetSearch = () => {
  searchComplaintForm.value = {};//清空投诉数据表单数据
  loadComplaint();//重新加载投诉数据
}

</script>